package org.elephas.webapp.frontend.component.links;

import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.util.string.Strings;
import org.elephas.webapp.frontend.page.blog.BlogFrontPage;
import org.elephas.webapp.model.DetachableBlogModel;

/**
 * @author Gerolf Seitz
 * 
 */
public class BookmarkableBlogLink extends BookmarkablePageLink {
	private static final long serialVersionUID = 1L;

	private DetachableBlogModel blogModel;

	public BookmarkableBlogLink(String id, DetachableBlogModel model) {
		super(id, BlogFrontPage.class, BlogFrontPage
				.constructPageParameters(model.getObject()));
		blogModel = model;
	}

	@Override
	protected void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) {
		String name = getModelObjectAsString();
		name = Strings.isEmpty(name) ? blogModel.getObject().getName() : name;
		replaceComponentTagBody(markupStream, openTag, name);
	}
}
